package com.example.paging.ui

import androidx.lifecycle.*
import com.example.paging.repository.ArticleRepository

class StringViewModel(countRes: Int) : ViewModel() {

    private val _counter = MutableLiveData<Int>()


    init {
        _counter.value = countRes
    }

    val counter: LiveData<Int> get() = _counter

    val user = Transformations.switchMap(_counter) { page ->
        ArticleRepository.getHomeVo(page)
    }

    fun changeStr() {
        val count = _counter.value ?: 0
        _counter.value = count + 1
    }
}

class StringViewModelFactory(private val countRes: Int) : ViewModelProvider.Factory {
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        return modelClass.getConstructor(Int::class.java).newInstance(countRes)
    }
}